import Ember from 'ember';

export default Ember.Component.extend({
  classNames: ['inline-div'],
  showMenus: Ember.computed('selectedState', function() {
    var allMenus = this.get('menus'),
      st = this.get('selectedState');
    if (!allMenus)  {
      alert("please add menus property to list controller, even a empty menus.");
    }
    return allMenus.filter((it) => {
      return (it.showWhen === 'always') || st[it.showWhen];
    });
  }),
  showConfirm: false,
  actions: {
    menuClicked(mname) {
        if (mname === 'delete') {
          this.toggleProperty("showConfirm");
        } else {
          this.sendAction('action', mname);
        }
      },
      deleteConfirm(confirm) {
        if (confirm) {
          this.sendAction('action', 'delete');
        }
        this.toggleProperty("showConfirm");
      }
  }
});
